﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ninject;
using System.Web.Mvc;
using SportsStore.Domain.Abstract;
//using SportsStore.Domain.FakeRepository;
using SportsStore.Domain.Concrete;
using SportsStore.WebUI.Infrastructure.Abstract;
using SportsStore.WebUI.Infrastructure.Concrete;


namespace SportsStore.WebUI.Infrastructure
{
    public class NinjectControllerFactory:DefaultControllerFactory
    {
        private IKernel ninjectKernel;
        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
//            return base.GetControllerInstance(requestContext, controllerType);
            return controllerType == null ? null : (IController)ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            //addtional bindings
            ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>();
            ninjectKernel.Bind<IDocumentRepository>().To<EFDocumentRepository>();
            ninjectKernel.Bind<IOrderProcessor>()
                         .To<EmailOrderProcessor>()
                         .WithConstructorArgument("settings", new EmailSettings());
            ninjectKernel.Bind<IAuthProvider>().To<FormAuthProvider>();
            ninjectKernel.Bind<ICategoryRepository>().To<EFCategoryRepository>();
        }
    }
}